/* Examples/jerasure_01.cpp
 * James S. Plank

Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure Coding Techniques
Copright (C) 2007 James S. Plank

James S. Plank
Department of Electrical Engineering and Computer Science
University of Tennessee 
Knoxville, TN 37996
plank@cs.utk.edu
*/

/*
 * $Revision: 1.2 $
 * $Date: 2008/08/19 17:41:40 $ 
 */


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include "jerasure-2.h"

#define talloc(type, num) (type *) malloc(sizeof(type)*(num))

void usage(char *s)
{
  fprintf(stderr, "usage: jerasure_01 r c w - creates and prints out a matrix in GF(2^w).\n\n");
  fprintf(stderr, "       Element i,j is equal to 2^(i*c+j)\n");
  fprintf(stderr, "       \n");
  fprintf(stderr, "This demonstrates JER_Matrix::Print().\n");
  if (s != NULL) fprintf(stderr, "%s\n", s);
  exit(1);
}

int main(int argc, char **argv)
{
  int r, c, w, i, n, j;
	JER_Matrix *jm;

  if (argc != 4) usage(NULL);
  if (sscanf(argv[1], "%d", &r) == 0 || r <= 0) usage((char *)"Bad r");
  if (sscanf(argv[2], "%d", &c) == 0 || c <= 0) usage((char *)"Bad c");
  if (sscanf(argv[3], "%d", &w) == 0 || w <= 0) usage((char *)"Bad w");

  jm = new JER_Matrix(r, c, w);

  n = 1;
	for (i = 0; i < r; i++) {
		for (j = 0; j < c; j++) {
			jm->Elts[i][j] = n;
			n = galois_single_multiply(n, 2, w);
		}
	}

	jm->Print();
  return 0;
}

